package com.zzf.concurrent.example.daemon;

import lombok.extern.slf4j.Slf4j;

/**
 * @author GaoFeng2017
 * @date 2019/8/5 10:09
 */
@Slf4j
public class DaemonThreadExample2 {

    public static void main(String[] args) {

        Thread t1 = new Thread() {
            @Override
            public void run() {
                Thread innerThread = new Thread() {
                    @Override
                    public void run() {
                        while (true) {
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            log.info("发送心跳包");
                        }
                    }
                };

                innerThread.setDaemon(true);
                innerThread.start();
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                log.info("聊天室关闭");
            }
        };

        t1.start();

    }

}
